<style scoped>

</style>
<template>
    <div class="create-inquiry-sheet-page">
        <el-form :inline="true" :model="formInline" ref="formInline" class="demo-form-inline" style="border-bottom:1px solid #ccc;">
            <!--询价单号-->
            <el-form-item :label="nowLangue.inquiryNo">
                <el-input size="mini" disabled v-model="formInline.requestForQuotationId" placeholder=""></el-input>
            </el-form-item>
            <!--询价日期-->
            <el-form-item :label="nowLangue.inquiryDate">
                <el-input size="mini" disabled v-model="formInline.createTime" placeholder=""></el-input>
            </el-form-item>
            <!--询价人员-->
            <el-form-item :label="nowLangue.inquiryPersonnel">
                <el-input size="mini" disabled v-model="formInline.creatorName" placeholder=""></el-input>
            </el-form-item>
            <!--法人名称-->
            <el-form-item :label="nowLangue.legalName" prop="legalPersonId"  :rules="[{ required: true, message: nowLangue.required}]">
                <el-input size="mini" v-if="legalPersonDropDown.length == 1" disabled v-model.trim="formInline.legalPersonName" placeholder=""></el-input>
                <el-select size="mini" v-else v-model="formInline.legalPersonId" @change="changeLegalPerson">
                    <el-option v-for="(legalPerson,index) in legalPersonDropDown" :key="index" :label="legalPerson.legalPersonName" :value="legalPerson.id"></el-option>
                </el-select>
            </el-form-item>
            <!--询价类型-->
            <el-form-item :label="nowLangue.inquiryType" prop="type"  :rules="[{ required: true, message: nowLangue.required}]">
                <el-select size="mini" v-model="formInline.type" :placeholder="nowLangue.pleaseSelect" @change="selectTypeCode">
                    <el-option v-for="(inquiryType,index) in selectDropdown.type" :key="index" :label="inquiryType.label" :value="inquiryType.value"></el-option>
                </el-select>
            </el-form-item>
            <!--询价币别-->
            <el-form-item :label="nowLangue.inquiryCurrency" prop="currencyCode"  :rules="[{ required: true, message: nowLangue.required}]">
                <el-select size="mini" v-model="formInline.currencyCode" :placeholder="nowLangue.pleaseSelect" @change="selectCurrencyCode">
                    <el-option v-for="(inquiryCurrency,index) in selectDropdown.currencyCode" :key="index" :label="inquiryCurrency.label" :value="inquiryCurrency.value"></el-option>
                </el-select>
            </el-form-item>
            <!--金额是否含税-->
            <el-form-item :label="nowLangue.isTax"  prop="isTax"  :rules="[{ required: true, message: nowLangue.required}]">
                <el-select size="mini" v-model="formInline.isTax" :placeholder="nowLangue.pleaseSelect">
                    <el-option v-for="(isIncludeTax,index) in selectDropdown.isTax" :key="index" :label="isIncludeTax.label" :value="isIncludeTax.value"></el-option>
                </el-select>
            </el-form-item>
            <!--询价开始日期-->
            <el-form-item :label="nowLangue.inquiryStartDate"  prop="startTime"  :rules="[{ required: true, message: nowLangue.required}]">
                <el-date-picker type="date" size="mini" :editable="false" :clearable="false" v-model="formInline.startTime" :placeholder="nowLangue.pleaseSelect" :picker-options="pickerOptions" @change="selectedStartTime"></el-date-picker>
            </el-form-item>
            <!--询价结束日期-->
            <el-form-item :label="nowLangue.inquiryEndDate" prop="endTime"  :rules="[{ required: true, message: nowLangue.required}]">
                <el-date-picker type="date" size="mini" :editable="false" :clearable="false" v-model="formInline.endTime" :placeholder="nowLangue.pleaseSelect" :picker-options="pickerOptions" @change="selectedEndTime"></el-date-picker>
            </el-form-item>
            <el-form-item>
                <!--保存-->
                <el-button class="bolder outsideBtnBS selectAll" :disabled="saveDisabled" size="mini" type="danger" @click="save(10)" v-text="nowLangue.save"></el-button>
                <!--提交-->
                <el-button class="bolder outsideBtnBS" size="mini" type="danger" v-if="formInline.inquiryStatus==20" disabled v-text="nowLangue.submit"></el-button>
                <!--提交-->
                <el-button class="bolder outsideBtnBS selectAll" :disabled="submitDisabled" size="mini" type="danger" v-else @click="onSubmit(20)" v-text="nowLangue.submit"></el-button>
            </el-form-item>
            <!-- 
            <el-form-item>
                <el-button class="bolder outsideBtnBS" size="mini" type="danger" @click="handleReview">审核</el-button>
            </el-form-item>
            <el-form-item>
                <el-button class="bolder outsideBtnBS" size="mini" type="danger" @click="handleApprove">审批</el-button>
            </el-form-item>
            -->
        </el-form>
        <!--待询价明细表格-->
        <!-- 待询价明细：-->
        <label class="default-label" v-text="nowLangue.inquiryDetails"></label>
        <!--导入-->
        <el-button class="bolder outsideBtnBS" size="mini" type="danger" @click="leadingInMask" v-text="nowLangue.import"></el-button>
        <!--新增-->
        <el-button class="bolder outsideBtnBS" size="mini" type="danger"  @click="addSpare" v-text="nowLangue.create"></el-button>
        <el-table :data="inquiryDetailsData" border style="width: 100%;" v-loading.body="loading" element-loading-text="拼命加载中">
            <!--序-->
            <el-table-column type="index" header-align="center" align="center" :label="nowLangue.sequence"  width="40"></el-table-column>
            <!--操作-->
            <el-table-column :label="nowLangue.operate" header-align="center" align="center" width="80">
                <template scope="scope">
                    <!--删除-->
                    <div class="operationItem bolder"  @click="handleDel(scope.$index, inquiryDetailsData)" v-text="nowLangue.delete"></div>
                </template>
            </el-table-column>
            <!--备件编码-->
            <el-table-column prop="spareCoding" :label="nowLangue.spareCode" header-align="center" show-overflow-tooltip></el-table-column>
            <!--备件名称-->
            <el-table-column prop="spareName" :label="nowLangue.spareName" header-align="center" show-overflow-tooltip></el-table-column>
            <!--计量单位-->
            <el-table-column prop="measurementUnit" :label="nowLangue.materialUnit" header-align="center" width="120" show-overflow-tooltip></el-table-column>
            <!--询价数量-->
            <el-table-column prop="inquiryQty" :label="nowLangue.inquiryQty" header-align="center" width="120">
                <template scope="scope">
                    <el-input size="mini"  v-model.number="scope.row.inquiryQty" :placeholder="nowLangue.pleaseImport"  @change="inputInquiryQty(scope.$index, scope.row)"></el-input>
                </template>
            </el-table-column>
            <!--币别-->
            <el-table-column prop="currencyCodeWord" :label="nowLangue.currencyCode" header-align="center" width="80" show-overflow-tooltip></el-table-column>
            <el-table-column prop="moq" label="MOQ" header-align="center" width="180">
                <template scope="scope">
                    <el-input size="mini"  v-model.number="scope.row.moq" :placeholder="nowLangue.pleaseImport" @change="inputMOQ(scope.$index,scope.row)"></el-input>
                </template>
            </el-table-column>
            <!--交货周期(天)-->
            <el-table-column prop="deliveryCycle" :label="nowLangue.deliveryCycle" header-align="center" width="180">
                <template scope="scope">
                    <el-input size="mini"  v-model.number="scope.row.deliveryCycle" :placeholder="nowLangue.pleaseImport"  @change="inputDeliveryCycle(scope.$index, scope.row)"></el-input>
                </template>
            </el-table-column>

        </el-table>
        <!-- 待报价供应商明细 -->
        <label class="default-label" v-text="nowLangue.listOfSuppliersToBeQuoted"></label>
        <!--新增-->
        <el-button class="bolder outsideBtnBS" size="mini" type="danger" @click="addSupplier(supplierType)" v-text="nowLangue.create"></el-button>
        <el-table :data="supplierDetailsData" border style="width: 60%;" v-loading.body="loading" element-loading-text="拼命加载中">
            <!--序-->
            <el-table-column type="index" header-align="center" align="center" :label="nowLangue.sequence"  width="40"></el-table-column>
            <!--操作-->
            <el-table-column :label="nowLangue.operate" header-align="center" align="center" width="80">
                <template scope="scope">
                    <!--删除-->
                    <div class="operationItem bolder" @click="delSupplier(scope.$index, supplierDetailsData)" v-text="nowLangue.delete"></div>
                </template>
            </el-table-column>
            <!--供应商编码-->
            <el-table-column prop="vendorCode" :label="nowLangue.supplierNo" header-align="center" show-overflow-tooltip></el-table-column>
            <!--供应商名称-->
            <el-table-column prop="vendor" :label="nowLangue.supplierName" header-align="center" show-overflow-tooltip></el-table-column>
        </el-table>
         <!--导入的弹框-->
        <!--导入备件信息-->
        <el-dialog :title="nowLangue.importSpareMsg" id="LeadIngInMark" :visible.sync="leadIngInVisible" size="tiny" :lock-scroll="false">
            <el-upload class="upload-demo"  :action="action" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel" :on-preview="handlePreview" :on-remove="handleRemove" :file-list="fileList" :before-upload="beforeAvatarUpload" :on-success="handleAvatarSuccess">
                <!--点击上传-->
                <el-button size="mini" type="danger" v-text="nowLangue.clickUpload"></el-button>
                <!--只能上传excel文件-->
                <div slot="tip" class="el-upload__tip" v-text="nowLangue.uploadTip"></div>
            </el-upload>
        </el-dialog>
        
         <!-- 新增按钮的弹窗   选择备件 -->
        <el-dialog id="selectSparePartsMask" :title="nowLangue.selectSpare" :visible.sync="selectSparePartsVisible" size="small" :lock-scroll="false">
            <el-form :inline="true" :model="selectSparePartsForm" class="demo-form-inline">
                <!--备件编号-->
                <el-form-item :label="nowLangue.spareCode">
                    <el-input size="mini" v-model="selectSparePartsForm.spareCode" auto-complete="off" :placeholder="nowLangue.pleaseImport+nowLangue.spareCode"></el-input>
                </el-form-item>
                <!--备件名称-->
                <el-form-item :label="nowLangue.spareName">
                    <el-input size="mini" v-model="selectSparePartsForm.spareName" auto-complete="off" :placeholder="nowLangue.pleaseImport+nowLangue.spareName"></el-input>
                </el-form-item>
                <el-form-item>
                    <!--查询-->
                    <el-button class="bolder outsideBtnBS selectAll" :disabled="selectDisabled" size="mini" type="danger" @click="querySpareParts()" v-text="nowLangue.query"></el-button>
                    <!--确定-->
                    <el-button class="bolder outsideBtnBS" size="mini" type="danger" @click="determiningSpareParts" v-text="nowLangue.confirm"></el-button>
                </el-form-item>
            </el-form>
            <el-table :data="spareData" border style="width: 100%" @selection-change="selectSpare">
                <!--序-->
                <el-table-column type="index" header-align="center" align="center" :label="nowLangue.sequence"  width="40"></el-table-column>
                <!--操作-->
                <el-table-column type="selection" align="center"  width="40"></el-table-column>
                <!--备件编号-->
                <el-table-column property="code" :label="nowLangue.spareCode" header-align="center" show-overflow-tooltip></el-table-column>
                <!--备件名称-->
                <el-table-column property="name" :label="nowLangue.spareName" header-align="center" show-overflow-tooltip></el-table-column>
            </el-table>
            <span slot="footer" class="dialog-footer">
            <!--分页 v-if="isPaging"-->
            <el-pagination  @size-change="handleSpareSizeChange" @current-change="handleSpareCurrentChange" :current-page="sparePageIndex" :page-sizes="[1, 2, 3 , 4, 5]" :page-size="sparePageSize" layout="total, sizes, prev, pager, next, jumper" :page-count="spareTotalPage" :total="spareTotalNumber">
            </el-pagination>
            </span>
        </el-dialog>
        <!-- -->
        <!-- 新增按钮的弹窗   选择供应商 -->
        <el-dialog id="selectSppliersMask" :title="nowLangue.select+nowLangue.supplier" :visible.sync="selectSuppliersVisible" size="small" :lock-scroll="false">
            <el-form :inline="true" :model="selectSuppliersForm" class="demo-form-inline">
                <!--供应商编号-->
                <el-form-item :label="nowLangue.supplierNo">
                    <el-input size="mini" v-model="selectSuppliersForm.supplierCode" auto-complete="off" :placeholder="nowLangue.pleaseImport+nowLangue.supplierNo"></el-input>
                </el-form-item>
                <!--供应商名称-->
                <el-form-item :label="nowLangue.supplierName">
                    <el-input size="mini" v-model="selectSuppliersForm.supplierName" auto-complete="off" :placeholder="nowLangue.pleaseImport+nowLangue.supplierName"></el-input>
                </el-form-item>
                <el-form-item>
                    <!--查询-->
                    <el-button class="bolder outsideBtnBS selectAll" :disabled="selectDisabled" size="mini" type="danger" @click="querySuppliers()" v-text="nowLangue.query"></el-button>
                    <!--确定-->
                    <el-button class="bolder outsideBtnBS" size="mini" type="danger" @click="identifySuppliers" v-text="nowLangue.confirm"></el-button>
                </el-form-item>
            </el-form>
            <el-table :data="supplierData" border style="width: 100%" @selection-change="selectSupplier">
                <!--序-->
                <el-table-column property="id" :label="nowLangue.sequence" header-align="center" align="center"  width="40"></el-table-column>
                <el-table-column type="selection" align="center"  width="40"></el-table-column>
                <!--供应商编号-->
                <el-table-column property="partnerCode" :label="nowLangue.supplierNo" header-align="center" show-overflow-tooltip></el-table-column>
                <!--供应商名称-->
                <el-table-column property="partnerName" :label="nowLangue.supplierName" header-align="center" show-overflow-tooltip></el-table-column>
            </el-table>

            <div slot="footer" class="dialog-footer">
                <!-- v-if="isPaging" -->
                <el-pagination  @size-change="handleSupplierSizeChange" @current-change="handleSupplierCurrentChange" :current-page="supplierPageIndex" :page-sizes="[1, 2, 3 , 4, 5]" :page-size="supplierPageSize" layout="total, sizes, prev, pager, next, jumper" :page-count="supplierTotalPage" :total="supplierTotalNumber">
                </el-pagination>
            </div>
        </el-dialog>
        
    </div>
</template>


<script>

    export default {
        data() {
            return {
                pickerOptions: {     //询价开始日期/结束日期不得早于当天
                    disabledDate(time) {
                        return time.getTime() < Date.now() - 8.64e7;
                    }
                },
                nowLangue:{},
                // 查询表单
                formInline:{
                    id:"",
                    requestForQuotationId:"",
                    createTime:"",
                    creatorName:"",
                    legalPersonId:"",
                    legalPersonName:"",
                    type:"",
                    typeName:"",
                    currencyCode:"",
                    currencyCodeWord:"",
                    isTax:"",
                    isTaxName:"",
                    startTime:"",
                    endTime:"",
                    legalPersonNameList:[]
                },
                legalPersonDropDown:[],
                loading:false,
                inquiryDetailsData: [],// 待询价明细表格
                supplierDetailsData:[],// 待报价供应商明细
                selectDropdown:[],  // 下拉列表的值
                spareData:[],    // 选择备件弹窗  
                // 选择备件弹窗的 分页
                // isPaging:true,
                selectSparePartsVisible:false,   //选择备件弹窗
                selectSparePartsForm:{
                    spareCode:"",
                    spareName:""
                },
                //选择备件弹窗的 分页
                sparePageIndex:1,    //当前页（必传）
                sparePageSize :5,   //每页多少条
                spareTotalNumber: 20,     //总条数
                spareTotalPage:2,    //总页数

                // 选择供应商弹窗的  分页
                selectSuppliersVisible:false,
                selectSuppliersForm:{
                    supplierId:"",
                    supplierCode:"",
                    supplierName:""
                },
                supplierData:[], //新增供应商弹框中，供应商的信息
                providerList:[],//新增供应商弹框中，选中的供应商的信息
                supplierType:1,
                supplierPageIndex:1,    //当前页（必传）
                supplierPageSize :5,
                supplierTotalNumber: 20,     //总条数
                supplierTotalPage:2,

             
                leadIngInVisible:false,   //导入弹窗
                action:"",
                fileList:[],

                inquiryDetailsList:[],   //修改传的一个参数（表格）
                supplierDetailsList:[],
                //查询禁用
                selectDisabled:false,
                saveDisabled:false,  // 保存禁用
                submitDisabled:false  // 提交禁用
            };
        },
        created:function(){
            var _this=this;
            _this.languageType=="zh"?_this.nowLangue=_this.language.zh:_this.nowLangue=_this.language.en;
        },
        computed:{
            // powerData(){
            //     return this.$store.state.powerData;
            // },
            languageType(){
                return this.$store.state.languageType;
            }
        },
        watch:{
            languageType(){
                var _this=this;
                _this.languageType=="zh"?_this.nowLangue=_this.language.zh:_this.nowLangue=_this.language.en;
            }
        },
        //进入页面立即运行此方法
        mounted: function () {
            var _this = this;
            _this.$store.commit('currentActive', 'CreateInquirySheet');
            // //ajax前后查询按钮禁用(保存、提交)
            // $(".selectAll").ajaxStart(function(){
            //     _this.selectDisabled=true;
            //     _this.saveDisabled=true;
            //     _this.submitDisabled=true;
            // });
            // $(".selectAll").ajaxStop(function(){
            //     _this.selectDisabled=false;
            //     _this.saveDisabled=false;
            //     _this.submitDisabled=false;
            // });
            _this.createInquerySheetDropdownValue();
            _this.legalPersonDropDownValue();
            _this.getUser();

            // _this.formInline.requestForQuotationId=_this.$route.query.requestForQuotationId;
            // 上传地址
            _this.action=_this.procurement_service+"quotation/InquiryIntroduction";
        },
        methods: {
            //获得指定人姓名 createPlan.creatorName
            getUser(){  //法人名称下拉列表值
                var _this = this;
                $.ajax({
                    type:'GET',
                    url:_this.procurement_service+"/plan/getUser",
                    cache:false,
                    success:function(data){
                        if(data.success){
                            _this.formInline.creatorName = data.data;
                        }else{
                            _this.common.errorTip(data.errorMessage);
                        }
                    }
                })
            },
            // 选择询价开始日期
            selectedStartTime(val){
                var _this=this;
                _this.formInline.startTime = val;
                if(_this.formInline.endTime && val >= _this.formInline.endTime){
                    var err=_this.languageType=="zh"?'询价开始日期不能大于等于询价结束日期':'The starting date of inquiry shall not be greater than the end date of inquiry';
                    _this.common.errorTip(err);
                    _this.formInline.startTime = "";
                };
            },
            // 选择询价结束日期
            selectedEndTime(val){
                var _this=this;
                _this.formInline.endTime = val;
                if(_this.formInline.startTime && val <= _this.formInline.startTime){
                    var err=_this.languageType=="zh"?'询价结束日期不能小于等于询价开始日期':'The end of inquiry shall not be less than the starting date of inquiry';
                    _this.common.errorTip(err);
                    _this.formInline.endTime = "";
                };
            },
            // 新增的接口  新增后保存/提交
            addData(inquiryStatus){
                var _this = this;
                // // 传值时 传code
                // for(var i=0;i<_this.selectDropdown.currencyCode.length;i++){
                //     if(_this.formInline.currencyCode == _this.selectDropdown.currencyCode[i].label){
                //         _this.formInline.currencyCode = _this.selectDropdown.currencyCode[i].value;
                //     }
                // }
                var tmp = {currencyCode:_this.formInline.currencyCode,requestForQuotationId:_this.formInline.requestForQuotationId,inquiryStatus:inquiryStatus,createTime:_this.formInline.createTime,legalPersonId:_this.formInline.legalPersonId,legalPersonName:_this.formInline.legalPersonName,type:Number(_this.formInline.type),isTax:Number(_this.formInline.isTax),startTime:_this.formInline.startTime,endTime:_this.formInline.endTime,inquiryDetailsList:_this.inquiryDetailsData,supplierDetailsList:_this.supplierDetailsData,};
                $.ajax({
                    url:_this.procurement_service+'inquiryList/add',
                    type:'POST',
                    cache:false,
                    data:JSON.stringify(tmp),
                    dataType:'JSON',
                    contentType:'application/json;charset=utf-8',
                    success:function(data){
                        if(data.success){
                            var success=_this.languageType=="zh"?'操作成功':'Successful operation';
                            _this.common.successTip(success);
                            _this.formInline.requestForQuotationId=data.data.requestForQuotationId;   //询价单号
                            _this.formInline.createTime=data.data.createTime;   //询价日期
                            if(inquiryStatus==20){
                                _this.$router.push("/InquirySheet");
                            }
                        }else{
                            _this.common.errorTip(data.errorMessage);
                        }
                    }
                })
            },
            
            // 修改的接口  修改后保存/提交
            updateData(inquiryStatus){
                var _this = this;
                // // 传值时 传code
                // for(var i=0;i<_this.selectDropdown.currencyCode.length;i++){
                //     if(_this.formInline.currencyCode == _this.selectDropdown.currencyCode[i].label){
                //         _this.formInline.currencyCode = _this.selectDropdown.currencyCode[i].value;
                //     }
                // }
                var tmp = {currencyCode:_this.formInline.currencyCode,requestForQuotationId:_this.formInline.requestForQuotationId,inquiryStatus:inquiryStatus,createTime:_this.formInline.createTime,legalPersonId:_this.formInline.legalPersonId,type:_this.formInline.type,isTax:_this.formInline.isTax,startTime:_this.formInline.startTime,endTime:_this.formInline.endTime,inquiryDetailsList:_this.inquiryDetailsData,supplierDetailsList:_this.supplierDetailsData};
                $.ajax({
                    url:_this.procurement_service+'inquiryList/update',
                    type:'POST',
                    cache:false,
                    data:JSON.stringify(tmp),
                    dataType:'JSON',
                    contentType:'application/json;charset=utf-8',
                    success:function(data){
                        if(data.success){
                            var success=_this.languageType=="zh"?'操作成功':'Successful operation';
                            _this.common.successTip(success);
                            if(inquiryStatus==20){
                                _this.$router.push("/InquirySheet");
                            }
                        }else{
                            _this.common.errorTip(data.errorMessage);
                        }
                    }
                })
            },
            //保存按钮
            save(inquiryStatus){
                var _this = this;
                _this.$refs["formInline"].validate((valid) => {
                    if (valid) {
                        if(_this.formInline.requestForQuotationId == "" || _this.formInline.requestForQuotationId == null){
                            _this.addData(inquiryStatus);
                        }else{
                            _this.updateData(inquiryStatus);
                        }
                    } else {
                        var  err=_this.common.formErrorInfo();
                        _this.common.errorTip(err);
                        return false;
                    }
                });
                
            },
            //提交按钮
            onSubmit(inquiryStatus){
                var _this = this;
                _this.$refs["formInline"].validate((valid) => {
                    if (valid) {
                        if(_this.formInline.requestForQuotationId == "" || _this.formInline.requestForQuotationId == null){
                            _this.addData(inquiryStatus);
                        }else{
                            _this.updateData(inquiryStatus);
                        }
                    } else {
                        var  err=_this.common.formErrorInfo();
                        _this.common.errorTip(err);
                        return false;
                    }
                });
            },
            legalPersonDropDownValue(){  //法人名称下拉列表值
                var _this = this;
                $.ajax({
                    type:'GET',
                    url:_this.procurement_service+"legalPerson/ofCurrentUser",
                    cache:false,
                    success:function(data){
                        if(data.success){
                            _this.legalPersonDropDown = data.data;
                            _this.formInline.legalPersonName = _this.legalPersonDropDown[0].legalPersonName;
                            _this.formInline.legalPersonId = _this.legalPersonDropDown[0].id;
                        }else{
                            _this.common.errorTip(data.errorMessage);
                        }
                    }
                })
            },
            // 选择法人 取名称给后台
            changeLegalPerson(){
                var _this = this;
                for(var i=0;i<_this.legalPersonDropDown.length;i++){
                    if(_this.formInline.legalPersonId==_this.legalPersonDropDown[i].id){
                        _this.formInline.legalPersonName=_this.legalPersonDropDown[i].legalPersonName;
                    }
                }
            },

            createInquerySheetDropdownValue(){ //下拉列表的值
                var _this =this;
                var tmp = ["type","isTax","currencyCode"];
                $.ajax({
                    type:'POST',
                    url:_this.procurement_service+'procurement/getPullDownList',
                    cache:false,
                    data:JSON.stringify(tmp),
                    dataType:'JSON',
                    contentType:"application/json;charset=utf-8",
                    success: function(data){
                        if(data.success){
                            _this.selectDropdown=data.data;
                        }else{
                            _this.common.errorTip(data.errorMessage);
                        }
                    }
                });
            },
            // 下拉列表 询价类别
            selectTypeCode(){
                var _this=this;
                for(var i=0;i<_this.inquiryDetailsData.length;i++){
                    _this.inquiryDetailsData[i].type=_this.formInline.type;
                }
            },
            // 下拉列表选择币别
            selectCurrencyCode(){
                var _this=this;
                // 表格中的币别显示汉字
                for(var i=0;i<_this.selectDropdown.currencyCode.length;i++){
                    if(_this.formInline.currencyCode == _this.selectDropdown.currencyCode[i].value){
                        _this.formInline.currencyCodeWord = _this.selectDropdown.currencyCode[i].label;
                    }
                }
                for(var i=0;i<_this.inquiryDetailsData.length;i++){
                    _this.inquiryDetailsData[i].currencyCode=_this.formInline.currencyCode;
                    _this.inquiryDetailsData[i].currencyCodeWord=_this.formInline.currencyCodeWord;
                }
            },
            //待询价明细 每行的删除按钮
            handleDel(index,rows){
                rows.splice(index,1);
            },
            // 待询价明细  导入按钮
            leadingInMask(){
                var _this=this;
                _this.leadIngInVisible = true;
                _this.fileList=[];
            },
            //上传之前的钩子
            beforeAvatarUpload(file) {
                const isExcel2007 = file.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
                const isExcel2003 = file.type === 'application/vnd.ms-excel';
                if (!isExcel2007 && !isExcel2003) {
                    var err=_this.languageType=="zh"?'只能上传excel文件':'You can upload only Excel files';
                    this.$message.error(err);
                }
                return isExcel2007 || isExcel2003 ;
            },
            //文件上传成功时的钩子
            handleAvatarSuccess(res, file){
                var _this=this;
                if(res.success){
                    _this.inquiryDetailsData = [];
                    for(var i=0;i<res.data.length;i++){
                         _this.inquiryDetailsData.push({
                            spareCoding:res.data[i].spareCoding,
                            spareName:res.data[i].spareName,
                            inquiryQty:res.data[i].inquiryQty,
                            measurementUnit:res.data[i].measurementUnit,
                            moq:res.data[i].moq,
                            deliveryCycle:res.data[i].deliveryCycle,
                            currencyCode:_this.formInline.currencyCode,
                            currencyCodeWord:_this.formInline.currencyCodeWord                            
                        });
                    }
                     _this.leadIngInVisible = false;
                    var success=_this.languageType=="zh"?'上传成功！':'Upload successfully!';
                    _this.common.successTip(success);
                }else{
                    _this.fileList=[];
                    _this.common.errorTip(res.errorMessage);
                }
            },
            handleRemove(file, fileList) {
                // console.log(file, fileList);
            },
            handlePreview(file) {
                // console.log(file);
            },
            
            // 待询价明细 新增按钮
            addSpare(){
                var _this =this;
                _this.selectSparePartsVisible=true;
                _this.querySpareParts();   // 查询备件
            },
            // 待询价明细新增按钮   选择备件弹窗 查询按钮
            querySpareParts(){
                var _this = this;
                var tmp= {pageSize: _this.sparePageSize,pageIndex:_this.sparePageIndex,name:_this.selectSparePartsForm.spareName,code:_this.selectSparePartsForm.spareCode};
                $.ajax({
                    type:'POST',
                    url:_this.procurement_service+'inquiryList/selectMaterial',
                    cache:false,
                    data:JSON.stringify(tmp),
                    dataType:'JSON',
                    contentType:'application/json;charset=utf-8',
                    success:function(data){
                        // console.log(data);
                        if(data.success){
                            _this.spareTotalPage=data.data.totalPage;
                            _this.spareTotalNumber=data.data.totalNumber;
                            _this.spareData=data.data.materialList;
                            _this.selectedSpareList=[];   // 打开弹窗选中的清空
                            $("#selectSparePartsMask .el-table").find(".el-checkbox__input").removeClass("is-checked");
                        }else{
                            _this.common.errorTip(data.errorMessage)
                        }
                    }
                })
            },
            //   选泽备件弹窗的分页
            handleSpareSizeChange(val) {
                // console.log(`每页 ${val} 条`);
                var _this=this;
                _this.sparePageSize=val;
                _this.querySpareParts();

            },
            //点击页码分页查询点击事件
            handleSpareCurrentChange(val) {
                // console.log(`当前页: ${val}`);
                var _this=this;
                _this.sparePageIndex=val;
                _this.querySpareParts();
            },
            // selection-change	当选择项发生变化时会触发该事件 
            selectSpare(val){
                var _this=this;
                _this.selectedSpareList =[];
                for(var i=0;i<val.length;i++){
                    _this.selectedSpareList.push({"spareName":val[i].name,"spareCoding":val[i].code,"measurementUnit":val[i].unit,"moq":val[i].volumeProductionMOQ});   //新增供应商弹框中，选中的供应商code
                }
            },
            // 待询价明细新增按钮   选择备件弹窗 确定按钮
            determiningSpareParts(){
                var _this = this;
                 _this.selectSparePartsVisible = false;
                 // 确定时 待询价明细不能重复添加
                var showSpareCoding="";
                for(var i=0;i<_this.inquiryDetailsData.length;i++){
                    showSpareCoding += _this.inquiryDetailsData[i].spareCoding;
                }
                for(var j=0;j<_this.selectedSpareList.length;j++){
                    if(showSpareCoding.indexOf(_this.selectedSpareList[j].spareCoding) == -1){  // 选中的供应商在待报价供应商明细表格中不存在
                        _this.inquiryDetailsData.push({
                            spareCoding:_this.selectedSpareList[j].spareCoding,
                            spareName:_this.selectedSpareList[j].spareName,
                            measurementUnit:_this.selectedSpareList[j].measurementUnit,
                            moq:_this.selectedSpareList[j].moq,
                            currencyCode:_this.formInline.currencyCode,
                            currencyCodeWord:_this.formInline.currencyCodeWord
                        });
                    }else{
                        var err=_this.languageType=="zh"?'备件已存在，不能重复选择！':'The spare parts already exist and cannot be selected repeatedly!';
                        _this.common.errorTip(_this.selectedSpareList[j].spareCoding + err);
                    }
                } 
            },
            // 输入询价数量
            inputInquiryQty(index,row){
                var _this=this;
                if(typeof(row.inquiryQty)!="number"){                
                    var err=_this.languageType=="zh"?'询价数量只能为数字！':'The quantity quoted is for figures only!';
                    _this.common.errorTip(err);
                    row.inquiryQty=1;
                }else if(row.inquiryQty==0){               
                    var err=_this.languageType=="zh"?'询价数量必须大于零！':'The inquiry quantity must be greater than zero!';
                    _this.common.errorTip(err);
                    row.inquiryQty=1;
                }
            },
             // 输入MOQ
            inputMOQ(index,row){
                var _this=this;
                if(typeof(row.moq)!="number"){             
                    var err=_this.languageType=="zh"?'MOQ只能为数字！':'MOQ can only be numbers!';
                    _this.common.errorTip(err);
                    row.moq=1;
                }else if(row.moq==0){         
                    var err=_this.languageType=="zh"?'MOQ必须大于零！':'MOQ must be greater than zero!';
                    _this.common.errorTip(err);
                    row.moq=1;
                }
            },
            // 交货周期（天）
            inputDeliveryCycle(index,row){
                 var _this=this;
                if(typeof(row.deliveryCycle)!="number"){          
                    var err=_this.languageType=="zh"?'交货周期（天）只能为数字！':'Delivery cycle (days) can only be numbers!';
                    _this.common.errorTip(err);
                    row.deliveryCycle=1;
                }else if(row.deliveryCycle==0){    
                    var err=_this.languageType=="zh"?'交货周期（天）必须大于零！':'Delivery cycle (days) must be greater than zero!';
                    _this.common.errorTip(err);
                    row.deliveryCycle=1;
                }
            },
            // 待报价供应商明细 每行的删除按钮
            delSupplier(index,rows){
                rows.splice(index,1)
            },
            //待报价供应商明细  新增按钮
            addSupplier(supplierType){
                var _this =this;
                _this.selectSuppliersVisible=true;
                _this.querySuppliers();
            },
            // 待报价供应商明细新增按钮   选择供应商弹窗 查询按钮
            querySuppliers(){
                var _this=this;
                var tmp={id:_this.selectSuppliersForm.supplierId,partnerName:_this.selectSuppliersForm.supplierName,partnerCode:_this.selectSuppliersForm.supplierCode,pageIndex:_this.supplierPageIndex,pageSize:_this.supplierPageSize};
                _this.selectDisabled=true;
                $.ajax({
                    type: 'POST',
                    url: _this.metadata_service+"material/searchPartnerPage",
                    cache: false,
                    data:JSON.stringify(tmp),
                    dataType:'JSON',
                    contentType: "application/json;charset=utf-8",     //*****
                    success: function (data) {
                        if (data.success) {
                            // console.log(data);
                            _this.supplierData=data.data.dataList;
                            _this.supplierTotalNumber=data.data.totalNumber;    //总条数
                            _this.supplierTotalPage=data.totalPage;    //总页数
                            // console.log('新增供应商弹窗中的数据列表!');
                            _this.providerList=[];
                            // $("#selectSppliersMask .el-table").find(".el-checkbox__input").removeClass("is-checked");

                        }else{
                            _this.common.errorTip(data.errorMessage);
                        }
                        _this.selectDisabled=false;    
                    }
                })
            },
            // selection-change	当选择项发生变化时会触发该事件 
            selectSupplier(val){
                var _this=this;
                _this.providerList = [];
                for(var i=0;i<val.length;i++){
                    _this.providerList.push({"id":val[i].id,"vendor":val[i].partnerName,"vendorCode":val[i].partnerCode});   //新增供应商弹框中，选中的供应商的信息
                }
            },

            //   选择供应商弹窗 确定按钮
            identifySuppliers(){
                var _this = this;
                _this.selectSuppliersVisible = false;
                // 确定时 待报价供应商明细不能重复添加
                var showVendorCode="";
                for(var i=0;i<_this.supplierDetailsData.length;i++){
                    showVendorCode +=_this.supplierDetailsData[i].vendorCode;
                }
                for(var j=0;j<_this.providerList.length;j++){
                    if(showVendorCode.indexOf(_this.providerList[j].vendorCode) == -1){  // 选中的供应商在待报价供应商明细表格中不存在
                        _this.supplierDetailsData.push({
                            vendorId:_this.providerList[j].id,
                            vendor:_this.providerList[j].vendor,
                            vendorCode:_this.providerList[j].vendorCode,
                        });
                    }else{
                        var err=_this.languageType=="zh"?'备件已存在，不能重复选择！':'The spare parts already exist and cannot be selected repeatedly!';
                        _this.common.errorTip(_this.providerList[j].vendorCode + err);
                    }
                }     
            },

            //   分页
            handleSupplierSizeChange(val) {
                // console.log(`每页 ${val} 条`);
                var _this=this;
                _this.supplierPageSize=val;
                _this.querySuppliers();
            },
            //点击页码分页查询点击事件
            handleSupplierCurrentChange(val) {
                // console.log(`当前页: ${val}`);
                var _this=this;
                _this.supplierPageIndex=val;
                _this.querySuppliers();
            },
            // // ===================================
            // successTip(p) {     //成功时的提示信息
            //     this.$notify({
            //         title: this.nowLangue.success,
            //         message: p,
            //         type: 'success'
            //     });
            // },
            // errorTip(p) {     //错误提示
            //     this.$notify.error({
            //         title: this.nowLangue.error,
            //         message: p
            //     });
            // }

        }
    }
</script>
<style scoped>
    .el-select .el-tag{
        margin: 0;
    }
    .el-select__tags .el-select__input {
        display: none;
    }
    .main-right .el-pagination{
        margin-top: 0;
    }
</style>